home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / lzw4c12.zip / MK_ARC.C < prev    next >
Text File  |  1992-11-08  |  2KB  |  95 lines

  1. /*
  2. **   MK_ARC.C       Copyright (C) 1992 by MarshallSoft Computing, Inc.
  3. **
  4. **   This program is used to compress one or more files into a single
  5. **   archive file. For example, to compress all files ending with the
  6. **   extension '.C' into an archive named 'C.ARF', type:
  7. **
  8. **      MK_ARC *.C C.ARF
  9. */
  10.  
  11. #include <stdio.h>
  12. #include <dos.h>
  13. #include <fcntl.h>
  14. #include <sys\types.h>
  15. #include <sys\stat.h>
  16. #include <io.h>
  17.  
  18. #include "LZW4C.H"
  19. #include "RW_IO.H"
  20. #include "DIR_IO.H"
  21.  
  22. extern char *malloc();
  23. extern int free();
  24.  
  25. void SayError(int);
  26.  
  27. void main(argc,argv)
  28. int argc;
  29. char *argv[];
  30. {int i, k;
  31.  int RetCode;
  32.  float Ratio;
  33.  long TotalCount = 0;
  34.  char Filename[15];
  35.  int Files = 0;
  36.  char *Ptr;
  37.  /* begin */
  38.  if(argc!=3)
  39.    {printf("Usage: MK_ARC <filespec> <archive_file_name>\n");
  40.     exit(1);
  41.    }
  42.  RetCode = InitLZW(malloc);
  43.  if(RetCode<0)
  44.    {SayError(RetCode);
  45.     exit(2);
  46.    }
  47.  /* flush the keyboard */
  48.  puts("\nMK_ARC 1.0: Type any key to abort...");
  49.  /* open output file for compression */
  50.  Ptr = argv[2];
  51.  for(i=0;i<strlen(Ptr);i++) Ptr[i] = toupper(Ptr[i]);
  52.  if(!WriterOpen(Ptr)) exit(4);
  53.  for(i=0;;i++)
  54.    {if(kbhit())
  55.       {puts("\n...Aborted by user !");
  56.        break;
  57.       }
  58.     if(i==0) RetCode = FindFirst(argv[1],Filename);
  59.     else RetCode = FindNext(Filename);
  60.     if(!RetCode) break;
  61.     /* make filename upper case */
  62.     for(k=0;k<strlen(Filename);k++) Filename[i] = toupper(Filename[i]);
  63.     /* open input file for compression */
  64.     if(strcmp(Filename,Ptr)==0)
  65.       {printf("WARNING: Compress file same as archive file = %s (skipping)\n",
  66.          Filename);
  67.        continue;
  68.       }
  69.     if(!ReaderOpen(Filename)) exit(3);
  70.     /* write filename to output file */
  71.     Writer('\0');
  72.     for(k=0;k<strlen(Filename);k++) Writer(Filename[k]);
  73.     Writer('\0');
  74.     /* do the compression */
  75.     Files++;
  76.     printf("Compressing %12s ",Filename);
  77.     if((RetCode=Compress(Reader,Writer))<0)
  78.       {SayError(RetCode);
  79.        exit(5);
  80.       }
  81.     /* report compression ratio */
  82.     if(ReaderCount() > 0)
  83.        {Ratio = (float)(WriterCount()-TotalCount)/(float)ReaderCount();
  84.         printf(" OK (%0.2f)\n",Ratio);
  85.         TotalCount = WriterCount();
  86.        }
  87.     else puts("???");
  88.     /* close file */
  89.     ReaderClose();
  90.    }
  91.  WriterClose();
  92.  TermLZW(free);
  93.  printf("\n%d files compressed\n",Files);
  94.  exit(0);
  95. }